package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author admin
 * @version 1.0.0
 * @time 2021/3/19 11:02
 * @desc 首页
 */
@Controller
@RequestMapping("/index")
public class IndexController {


    @RequestMapping("/index")
    public ModelAndView index() {

        List<Map<String, String>> list = this.getArticle();

        ModelAndView modelAndView = new ModelAndView("index.html");

        modelAndView.addObject("list", list);

        return modelAndView;
    }

    private List<Map<String, String>> getArticle() {
        List<Map<String, String>> list = new ArrayList<>();

        String title = "test";
        String content = "content";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < 5; i++) {
            Map<String, String> map = new HashMap<>();
            map.put("type", "默认分类");
            map.put("publishTime", sdf.format(new Date()));
            map.put("title", title + " >>> " + i);
            map.put("content", content + " >>> " + i);
            list.add(map);
        }
        return list;
    }

}
